﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LPV_POS.mh_pos.mh_cauhinh
{
    public partial class frmMau_Ban : Form
    {
        public frmMau_Ban()
        {
            InitializeComponent();
        }
        DataTable tbDM_BAN_TRANGTHAI = null;
        private void frmMau_Ban_Load(object sender, EventArgs e)
        {
            //DM_BAN.TRANGTHAI
            this.ShowData();

            this.Load_Table_Color();
        }
        void ShowData()
        {
            thuvien othuvien = new thuvien();
            string sSQL = "SELECT * FROM DM_BAN_TRANGTHAI";
            tbDM_BAN_TRANGTHAI = othuvien.SP_SelectDataTable("SP_EXECUTESQL",
                                                            new string[] { "@sSQL" },
                                                            new string[] { sSQL });
        }
        void Load_Table_Color()
        {
            try
            {
                if (tbDM_BAN_TRANGTHAI.Rows.Count >= 3)
                {
                    int iR = 0;
                    int iG = 0;
                    int iB = 0;
                    string sma = "";
                    Color cMauNen;
                    foreach (DataRow dr in tbDM_BAN_TRANGTHAI.Rows)
                    {
                        sma = dr["DM_BAN_TRANGTHAI_MA"] + "";
                        iR = int.Parse(dr["BAN_MAUNEN_Red"] + "");
                        iG = int.Parse(dr["BAN_MAUNEN_Green"] + "");
                        iB = int.Parse(dr["BAN_MAUNEN_Blue"] + "");
                        cMauNen = Color.FromArgb(iR, iG, iB);

                        if (sma == "1")
                            lbl0_chuacokhach.BackColor = cMauNen;
                        else if (sma == "2")
                            lbl1_chuakhach.BackColor = cMauNen;
                        else if (sma == "3")
                            lbl2_dadattruoc.BackColor = cMauNen;
                    }

                }
            }
            catch(Exception ex)
            {
                string s = ex.Message;
            }
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            thuvien othuvien = new thuvien();
            othuvien.SP_Update("sp_DM_BAN_TRANGTHAI",
                                new string[] { "@flag", "@DM_BAN_TRANGTHAI_MA", "@BAN_MAUNEN_Red", "@BAN_MAUNEN_Green", "@BAN_MAUNEN_Blue" },
                                new object[] { 1,1 + "", lbl0_chuacokhach.BackColor.R + "", lbl0_chuacokhach.BackColor.G + "", lbl0_chuacokhach.BackColor.B + "" });

            othuvien.SP_Update("sp_DM_BAN_TRANGTHAI",
                                            new string[] { "@flag", "@DM_BAN_TRANGTHAI_MA", "@BAN_MAUNEN_Red", "@BAN_MAUNEN_Green", "@BAN_MAUNEN_Blue" },
                                            new object[] { 1, 2 + "", lbl1_chuakhach.BackColor.R + "", lbl1_chuakhach.BackColor.G + "", lbl1_chuakhach.BackColor.B + "" });

            othuvien.SP_Update("sp_DM_BAN_TRANGTHAI",
                                            new string[] { "@flag", "@DM_BAN_TRANGTHAI_MA", "@BAN_MAUNEN_Red", "@BAN_MAUNEN_Green", "@BAN_MAUNEN_Blue" },
                                            new object[] { 1, 3, lbl2_dadattruoc.BackColor.R + "", lbl2_dadattruoc.BackColor.G + "", lbl2_dadattruoc.BackColor.B + "" });

            this.DialogResult = DialogResult.OK;
            Module.MessageBox_LPV.Show("Lưu thành công");
            this.Close();

        }

        private void bton_thoat_1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void lbl0_chuacokhach_Click(object sender, EventArgs e)
        {
            Label lblban = (Label)sender;
            mh_color omh_color = new mh_color();
            Color cmau = omh_color.ShowForm();
            if (omh_color.DialogResult == DialogResult.OK)
                lblban.BackColor = cmau;
        }
    }
}
